package com.blindBox.back.controller.getDataController;


import com.blindBox.back.annotation.JwtToken;
import com.blindBox.back.commonResult.MsgBackToFront;
import com.blindBox.back.service.PaperService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

//后台获取纸条需要的数据
@RestController
@RequestMapping("/paper")
public class BackDataPaperController
{
    private PaperService paperService;

    //总纸条数量
    @JwtToken
    @PostMapping("get_paper_num")
    public MsgBackToFront getAllPapers()
    {
        Integer paperNums = paperService.getPaperNums();
        return new MsgBackToFront(paperNums,MsgBackToFront.HANDLE_SUCCESS);
    }

    //剩余可用纸条数量
    @JwtToken
    @PostMapping("get_paper_able_num")
    public MsgBackToFront getAblePaperNums()
    {
        Integer ablePaperNums = paperService.getAblePaperNums();
        return  new MsgBackToFront(ablePaperNums,MsgBackToFront.HANDLE_SUCCESS);
    }

    //获取所有纸条
    @JwtToken
    @PostMapping("get_all_papers")
    public MsgBackToFront getAllPapersInfo()
    {
        List<Map<Object, Object>> papersInfo = paperService.getPapersInfo();
       return papersInfo!=null?
               new MsgBackToFront(papersInfo,MsgBackToFront.HANDLE_SUCCESS):
               new MsgBackToFront(null,MsgBackToFront.DATABASE_ERROR);
    }

    //删除纸条
    @JwtToken
    @PostMapping("del_paper_by_id")
    public MsgBackToFront delPaperById(@RequestParam("p_id")Integer p_id)
    {
        return paperService.delPaperById(p_id);
    }

}
